package com.sokal.easycare.modules.product.entity.catalog;

import org.hibernate.validator.constraints.Length;
import com.fasterxml.jackson.annotation.JsonBackReference;

import com.sokal.easycare.common.persistence.TreeEntity;

/**
 * 产品目录Entity
 * @author liliangdong
 * @version 2017-03-12
 */
public class ProCatalog extends TreeEntity<ProCatalog> {
	
	private static final long serialVersionUID = 1L;
	private String name;		// 目录名称
	private String code;		// 目录编码
	private ProCatalog parent;		// 产品目录
	private String parentIds;		// 父级IDS
	
	public ProCatalog() {
		super();
	}

	public ProCatalog(String id){
		super(id);
	}

	@Length(min=1, max=100, message="目录名称长度必须介于 1 和 100 之间")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@Length(min=0, max=50, message="目录编码长度必须介于 0 和 50 之间")
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}
	
	@JsonBackReference
	public ProCatalog getParent() {
		return parent;
	}

	public void setParent(ProCatalog parent) {
		this.parent = parent;
	}
	
	@Length(min=0, max=1000, message="父级IDS长度必须介于 0 和 1000 之间")
	public String getParentIds() {
		return parentIds;
	}

	public void setParentIds(String parentIds) {
		this.parentIds = parentIds;
	}
	
	public String getParentId() {
		return parent != null && parent.getId() != null ? parent.getId() : "0";
	}
}